package com.example.exp2;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;

import java.util.Objects;

@SuppressWarnings("unused")     //忽略没有进行类型检查操作的警告
public class CustomCommandLineRunner implements CommandLineRunner {

    private Environment env;

    public CustomCommandLineRunner(Environment env) {
        this.env=env;
    }

    @Override
    public void run(String... args){
        System.out.println("利用Spring Boot自动装配的CommandLineRunner!");
        /*使用Random的RandomValuePropertySource产生一个32位随机字串*/
        System.out.println("生成一个随机字串:".concat(Objects.requireNonNull(env.getProperty("random."))));
    }
}
